<?php
class category extends skeleton {
	function get_description($format = true) {
		return ($format === true) ? autop(abbr($this->description)) : $this->description;
	}
	
	function get_name() {
		return $this->name;
	}
	
	function get_permalink($format = true, $options = array()) {
		$permalink = (get_option('pretty_permalinks')) ? get_option('site_path').'category/'.$this->get_slug().'/' : get_option('site_path').'?category='.$this->get_slug();
		
		if ($format === true) {
			$options = array_merge(array(
				'text' => $this->get_name(),
				'title' => 'View all posts under '.$this->get_name(),
				'class' => ''
			), (array)$options);
			$options['href'] = $permalink;
			
			$permalink = make_link($options);
		}
		
		return $permalink;
	}
	
	function get_post_amount() {
		global $mysql;
		if (!isset($this->post_amount)) $this->post_amount = (int)mysql_result($mysql->query('SELECT COUNT(*) FROM `'.POSTS.'` WHERE FIND_IN_SET("'.$this->get_id().'", `post_category`)'), 0);
		
		return $this->post_amount;
	}
	
	function get_slug() {
		return $this->slug;
	}
	
	function the_name() {
		echo $this->get_name();
	}
	
	function the_description($format = true) {
		echo $this->get_description($format);
	}
	
	function the_permalink($format = true, $options = array()) {
		echo $this->get_permalink($format, $options);
	}
	
	function the_post_amount() {
		echo $this->get_post_amount();
	}
	
	function the_slug() {
		echo $this->get_slug();
	}
}
?>